package com.lg.partition24;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/4/20 10:48
 */
public class P2330SCOI2005_繁忙的都市 {

    private static final int N = 310, M = 100010;
    private static Edge[] edges = new Edge[M];
    private static int[] parent = new int[N];
    private static int n, m;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        m = nextInt();
        for (int i = 1; i <= n; i++) parent[i] = i;
        for (int i = 0; i < m; i++) {
            int a = nextInt(), b = nextInt(), w = nextInt();
            edges[i] = new Edge(a, b, w);
        }
        Arrays.sort(edges, 0, m);
        int ans = 0;
        for (int i = 0; i < m; i++) {
            int a = edges[i].u, b = edges[i].v, c = edges[i].w;
            int fa = find(a), fb = find(b);
            if (fa != fb) {
                parent[fa] = fb;
                ans = c;
            }
        }
        writer.format("%d %d\n", n - 1, ans);
        writer.flush();
    }

    private static int find(int x) {
        if (x != parent[x]) parent[x] = find(parent[x]);
        return parent[x];
    }

    private static class Edge implements Comparable<Edge> {
        private int u, v, w;

        public Edge(int u, int v, int w) {
            this.u = u;
            this.v = v;
            this.w = w;
        }

        @Override
        public int compareTo(Edge o) {
            return Integer.compare(w, o.w);
        }
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
